unit Player;

interface

uses Graphics, WinTypes, Types;

type

 TPlayer = class
 protected
  Avatar: Graphics.TBitmap;
  function InverseColor( color: TColor ): TColor;
 private
  Score: Integer;
 public
  constructor Create;
  procedure IncreasePoints(Amount: Integer);
  procedure MultipyPoints(Multipler: Integer);
  procedure DecreasePoints(Amount: Integer);
  procedure ClearPoints;
  function GetPoints: integer;
  procedure PerfromAMove(Board: TObject); virtual;
  function IsOwnMovable: Boolean; virtual;
  procedure Draw(Canvas: TCanvas; Focused: Boolean; BackgroundColor: TColor; TextLabel: String; Position: TPoint); virtual;
  function GetWidth(Canvas: TCanvas): Integer;
  function GetHeight(Canvas: TCanvas): Integer;
 end;

implementation

uses SysUtils;

function TPlayer.InverseColor( color: TColor ): TColor;
var
 rgb_: TColorRef;
  function Inv( b: Byte ): Byte;
  begin
    if b>128 Then
     result:= 0
    else
     result:= 255;
  end;
begin
 rgb_ := ColorToRgb( color );
 rgb_ := RGB( Inv(GetRValue( rgb_ )),
 Inv(GetGValue( rgb_ )),
 Inv(GetBValue( rgb_ )));
 Result := rgb_;
end;

function TPlayer.GetHeight(Canvas: TCanvas): Integer;
begin
 Result := Avatar.Height + 5;
end;

function TPlayer.GetWidth(Canvas: TCanvas): Integer;
begin
 Result := Avatar.Width + 5 + 55 + 5;
end;

procedure TPlayer.Draw(Canvas: TCanvas; Focused: Boolean; BackgroundColor: TColor; TextLabel: String; Position: TPoint);
begin
 Canvas.Draw(Position.X + 1, Position.Y + 1, Avatar);
 Canvas.Font.Size := 8;
 Canvas.Font.Color := InverseColor(BackgroundColor);
 Canvas.Brush.Style := bsClear;
 Canvas.Font.Style := Canvas.Font.Style + [fsBold];
 Canvas.TextOut(Position.X + 1 + Avatar.Width + 5, Position.Y + 2, TextLabel);
 Canvas.TextOut(Position.X + 1 + Avatar.Width + 5, Position.Y + 2 + Avatar.Height div 2, IntToStr(Score));
 Canvas.Font.Style := Canvas.Font.Style - [fsBold];

 if Focused then
  begin
   Canvas.Brush.Color := InverseColor(BackgroundColor);
   Canvas.Brush.Style := bsClear;
   Canvas.Pen.Color := InverseColor(BackgroundColor);
   Canvas.Pen.Width := 2;
   Canvas.Rectangle(Position.X, Position.Y, Position.X + Avatar.Width + 2, Position.Y + Avatar.Height + 2);
  end;

end;

function TPlayer.IsOwnMovable: boolean;
begin
 IsOwnMovable := false;
end;

procedure TPlayer.PerfromAMove(Board: TObject);
begin
 //nic nie musimy robic, domyslny gracz to czlowiek
end;

function TPlayer.GetPoints;
begin
 Result := Score;
end;

procedure TPlayer.ClearPoints;
begin
 Score := 0;
end;

procedure TPlayer.MultipyPoints(Multipler: Integer);
begin
 Score := Score * Multipler;
end;

procedure TPlayer.DecreasePoints(Amount: Integer);
begin
 Score := Score - Amount;
end;

procedure TPlayer.IncreasePoints(Amount: Integer);
begin
 Score := Score + Amount;
end;

constructor TPlayer.Create;
begin
 Score := 0;
 Avatar := Graphics.TBitmap.Create;
 Avatar.LoadFromFile('graph\human.bmp');
end;

end.
